<?php

// 发立得信息发布系统房屋信息版(php+mysql) V1.0
// 演示地址: http://fang.chalide.cn
// 文件路径: sys/site.php
// 文件大小: 4794 字节
// 最后修改时间: 2025-05-23 16:20:04
// 作者: yujianyue
// 邮件: 15058593138@qq.com
// 版权所有,保留发行权和署名权
/**
 * 本文件功能：网站设置
 * 版权声明：保留发行权和署名权
 * 作者信息：15058593138@qq.com
 */

// 获取当前用户
$curr_user = check_login(USER_TYPE_ADMIN);
$db = DB::getInstance();

// 获取站点配置
$site_config = get_site_config();

// 处理AJAX请求
if (isset($_GET['act'])) {
    $act = $_GET['act'];
    
    switch ($act) {
        // 保存设置
        case 'save':
            $data = [
                'site_name' => isset($_POST['site_name']) ? $_POST['site_name'] : $site_config['site_name'],
                'site_desc' => isset($_POST['site_desc']) ? $_POST['site_desc'] : $site_config['site_desc'],
                'site_keywords' => isset($_POST['site_keywords']) ? $_POST['site_keywords'] : $site_config['site_keywords'],
                'version' => isset($_POST['version']) ? $_POST['version'] : $site_config['version'],
                'upload_max_size' => isset($_POST['upload_max_size']) ? intval($_POST['upload_max_size']) * 1024 * 1024 : $site_config['upload_max_size'],
                'admin_email' => isset($_POST['admin_email']) ? $_POST['admin_email'] : $site_config['admin_email'],
                'copyright' => isset($_POST['copyright']) ? $_POST['copyright'] : $site_config['copyright'],
                'beian' => isset($_POST['beian']) ? $_POST['beian'] : $site_config['beian'],
            ];
            
            // 保存配置
            if (save_site_config($data)) {
                json_msg(1, '保存成功');
            } else {
                json_msg(0, '保存失败，请检查文件权限');
            }
            break;
            
        default:
            json_msg(0, '未知操作');
    }
    
    exit;
}
    include './inc/head.php';
?>

<div class="site-container" style="background:#fff;padding:20px;border-radius:5px;box-shadow:0 1px 3px rgba(0,0,0,0.1);">
    <h2 style="margin-bottom:20px;">网站设置</h2>
    
    <form id="site-form">
        <div class="form-group">
            <label class="form-label">网站名称</label>
            <input type="text" name="site_name" class="form-control" value="<?php echo $site_config['site_name']; ?>">
        </div>
        
        <div class="form-group">
            <label class="form-label">网站描述</label>
            <input type="text" name="site_desc" class="form-control" value="<?php echo $site_config['site_desc']; ?>">
        </div>
        
        <div class="form-group">
            <label class="form-label">网站关键词</label>
            <input type="text" name="site_keywords" class="form-control" value="<?php echo $site_config['site_keywords']; ?>">
        </div>
        
        <div class="form-group">
            <label class="form-label">版本号</label>
            <input type="text" name="version" class="form-control" value="<?php echo $site_config['version']; ?>">
        </div>
        
        <div class="form-group">
            <label class="form-label">上传文件大小限制（MB）</label>
            <input type="number" name="upload_max_size" class="form-control" value="<?php echo $site_config['upload_max_size'] / 1024 / 1024; ?>">
        </div>
        
        <div class="form-group">
            <label class="form-label">管理员邮箱</label>
            <input type="email" name="admin_email" class="form-control" value="<?php echo $site_config['admin_email']; ?>">
        </div>
        
        <div class="form-group">
            <label class="form-label">版权信息</label>
            <input type="text" name="copyright" class="form-control" value="<?php echo $site_config['copyright']; ?>">
        </div>
        
        <div class="form-group">
            <label class="form-label">备案号</label>
            <input type="text" name="beian" class="form-control" value="<?php echo $site_config['beian']; ?>">
        </div>
        
        <div class="form-group">
            <button type="button" id="submit-btn" class="btn btn-primary">保存设置</button>
        </div>
    </form>
</div>

<script>
document.addEventListener('DOMContentLoaded', function() {
    const submitBtn = document.getElementById('submit-btn');
    const siteForm = document.getElementById('site-form');
    
    // 提交按钮点击事件
    submitBtn.addEventListener('click', function() {
        // 获取表单数据
        const formData = getFormData('site-form');
        
        // 提交修改
        ajax({
            url: 'sys.php?do=site&act=save',
            method: 'POST',
            data: formData,
            success: function(res) {
                showToast(res.msg);
            },
            error: function() {
                showToast('网络错误，请稍后重试');
            }
        });
    });
});
</script>
